from django.db.models import Sum
from django.core.cache import cache
from django.conf import settings
from django.contrib.auth import get_user_model
UserModel = get_user_model()
redis_prefix = settings.REDIS_PREFIX



def get_user_count():
    key = redis_prefix + 'UserCount'
    if not cache.has_key(key):
        cache.set(key, UserModel.objects.all().count(), 60 * 60)
    return cache.get(key)


def get_pre_deposit_count():
    key = redis_prefix + 'PreDepositSum'
    if not cache.has_key(key):
        cache.set(key, UserModel.objects.aggregate(Sum('preDeposit'))['preDeposit__sum'], 60 * 60)
    return cache.get(key)
